<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .el-page-header__content{
            color: white;
        }
    </style>
</head>
<body>
<div id="app">
    <el-page-header style="background-color: #363636;color: white;line-height: 60px"
                    @back="goBack" content="添加业主信息">
    </el-page-header>
    <div style="margin: 0 auto">
        <img src="img/logo.jpg" style="margin-left: 700px">
    </div>
    <el-card style="width: 600px;height: 700px;margin: 0 auto">
        <el-form label-width="80px">
            <el-form-item label="业主姓名">
                <el-input v-model="p.name" type="text"></el-input>
            </el-form-item>
            <el-form-item label="业主昵称">
                <el-input v-model="p.nickname" type="text"></el-input>
            </el-form-item>
            <el-form-item label="业主性别">
                <el-input v-model="p.gender" type="text"></el-input>
            </el-form-item>
            <el-form-item label="业主电话">
                <el-input v-model="p.tel" type="text"></el-input>
            </el-form-item>
<!--            <el-form-item label="购买时间">-->
<!--                <el-input v-model="p.created" type="text"></el-input>-->
<!--            </el-form-item>-->
            <el-form-item label="车牌号">
                <el-input v-model="p.carNumberId" type="text"></el-input>
            </el-form-item>
<!--            <el-form-item label="地址">-->
<!--                <el-select placeholder="车位分类" v-model="p.addressId">-->
<!--                    <el-option v-for="c in arr" :label="c.pos" :value="c.id"></el-option>-->
<!--                </el-select>-->
<!--            </el-form-item>-->
            <el-form-item label="详细地址">
                <el-input v-model="p.addressId" type="text"></el-input>
            </el-form-item>

            <el-form-item label="车位图片">
                <el-upload
                        action="/upload"
                        name="picFile"
                        limit="1"
                        list-type="picture-card"
                        :on-preview="handlePictureCardPreview"
                        :on-success="handleSuccess"
                        :on-remove="handleRemove">
                    <i class="el-icon-plus"></i>
                </el-upload>
                <el-dialog :visible.sync="dialogVisible">
                    <img width="100%" :src="dialogImageUrl" alt="">
                </el-dialog>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="insert()">添加信息</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</div>
</body>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>=
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                p: {
                    name:"",nickname:"",gender:"",
                    tel:"",created:"",carNumberId:"",addressId:"",url:""
                }
            }
        },
        methods: {
            //添加
            insert(){
                if(v.p.url==""){
                    confirm("请上传照片！")
                    /*v.$message.error 和 confirm的区别*/
                    return;
                }
                axios.post("/person/insert",v.p).then(function(response){
                    location.href="/person.html"
                })
            },
            goBack() {
                //返回上一页面
                history.back();
            },
            //图片上传成功
            handleSuccess(response,file,fileList) {
                v.p.url=response;
            },
            //删除图片
            handleRemove(file,fileList) {
                v.p.url="";
                axios.get("/remove?url="+file.response).then(function (response) {
                    console.log("删除文件成功！")
                })
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            }
        },
        created: function () {
            //发请求获取所有分类数据(car_position表，显示在插入时的分类)
            // axios.get("/position/select").then(function (response) {
            //     v.arr=response.data;
            // })
        }
    })
</script>
</html>